﻿using System;
using System.Web.UI.WebControls;

public partial class aspx_admin_hdly_insert : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            (this.FormView1.FindControl("显示CheckBox") as CheckBox).Checked = true;
        }
    }

    protected void FormView1_ItemInserting(object sender, FormViewInsertEventArgs e)
    {
        FileUpload fuxiao = this.FormView1.FindControl("FileUpload1") as FileUpload;
        if (!fuxiao.HasFile)
        {
            WebHelper.MessageBox.Show("请添加小图片");
            return;
        }
        try
        {
            Guid id = Guid.NewGuid();
            string filename = id.ToString() + System.IO.Path.GetExtension(fuxiao.FileName);
            WebHelper.WebControls.UploadFile(
                     fuxiao,
                     "~/images/hdly/small/",
                     new string[] { ".jpg", ".bmp" },
                     filename,
                     false,
                     int.MaxValue);
            e.Values["小图片"] = string.Format("~/images/hdly/small/{0}", filename);
            ImageCroper.ChangeWidthAndHeight(e.Values["小图片"] as string, 182, 121);
        }
        catch (Exception)
        {
            e.Cancel = true;
            throw;
        }
        WebHelper.MessageBox.Show("发布成功！");
    }
}